package scau.zxck.view.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import scau.zxck.utils.PropUtil;
import scau.zxck.view.Main;
import scau.zxck.view.stage.AlertStage;
import java.io.IOException;

/**
 * Created by chenyulin on 2016/11/30.
 */
public class AboutController {

    @FXML private Button btVisit;
    @FXML private Button btClose;
    @FXML private ImageView imgLogo;
    @FXML private Label lbNameAndVersion;
    @FXML private Label lbReleasedDate;
    private String softwareName = PropUtil.getBasicProp("Software_Name");
    private String version = PropUtil.getBasicProp("Version");
    private String releasedDate = PropUtil.getBasicProp("Released_Date");
    private String officialWebSiteUrl = PropUtil.getBasicProp("Official_Website_Url");

    public void initialize() {
        imgLogo.setImage(new Image("image/zxck_logo.png"));
        lbNameAndVersion.setText(softwareName + " v" + version);
        lbReleasedDate.setText("Released on " + releasedDate);
    }

    @FXML
    public void visitAction() {
        try {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + officialWebSiteUrl);
        } catch (IOException e) {
            new AlertStage("Error", "Failed to open website").show();
            e.printStackTrace();
        }
    }

    @FXML
    public void closeAction() {
        Main.aboutStage.close();
    }
}
